﻿using System.Collections.Generic;
using K9Nano.Share;
using Microsoft.AspNetCore.Http;

namespace K9Nano.AspNetCore.Extensions
{
    public static class HttpRequestExtensions
    {
        public static string CreateUri(this HttpRequest request, string relativeUrl)
        {
            var uri = $"{request.Scheme}://{request.Host}" +
                      (relativeUrl.StartsWith('/') ? relativeUrl : ('/' + relativeUrl));
            return uri;
        }

        public static string CreateUri(this HttpRequest request, string relativeUrl, IDictionary<string, string> query)
        {
            var uri = CreateUri(request, relativeUrl);

            uri = QueryHelpers.AddQueryString(uri, query);

            return uri;
        }
    }
}